package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserProfile;
import com.ruoyi.system.service.IUserProfileService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户实名档案Controller
 * 
 * @author Jack
 * @date 2025-07-02
 */
@Controller
@RequestMapping("/system/profile")
public class UserProfileController extends BaseController
{
    private String prefix = "system/profile";

    @Autowired
    private IUserProfileService userProfileService;

    @RequiresPermissions("system:profile:view")
    @GetMapping()
    public String profile()
    {
        return prefix + "/profile";
    }

    /**
     * 查询用户实名档案列表
     */
    @RequiresPermissions("system:profile:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserProfile userProfile)
    {
        startPage();
        List<UserProfile> list = userProfileService.selectUserProfileList(userProfile);
        return getDataTable(list);
    }

    /**
     * 导出用户实名档案列表
     */
    @RequiresPermissions("system:profile:export")
    @Log(title = "用户实名档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserProfile userProfile)
    {
        List<UserProfile> list = userProfileService.selectUserProfileList(userProfile);
        ExcelUtil<UserProfile> util = new ExcelUtil<UserProfile>(UserProfile.class);
        return util.exportExcel(list, "用户实名档案数据");
    }

    /**
     * 新增用户实名档案
     */
    @RequiresPermissions("system:profile:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户实名档案
     */
    @RequiresPermissions("system:profile:add")
    @Log(title = "用户实名档案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserProfile userProfile)
    {
        return toAjax(userProfileService.insertUserProfile(userProfile));
    }

    /**
     * 修改用户实名档案
     */
    @RequiresPermissions("system:profile:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UserProfile userProfile = userProfileService.selectUserProfileById(id);
        mmap.put("userProfile", userProfile);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户实名档案
     */
    @RequiresPermissions("system:profile:edit")
    @Log(title = "用户实名档案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserProfile userProfile)
    {
        return toAjax(userProfileService.updateUserProfile(userProfile));
    }

    /**
     * 删除用户实名档案
     */
    @RequiresPermissions("system:profile:remove")
    @Log(title = "用户实名档案", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userProfileService.deleteUserProfileByIds(ids));
    }
}
